<%
//---------------------------------------------------------------------------------------------
//	1. 파일명		    : zipcode_i1.jsp
//	2. 작성일자		    : 2007. 4. 19
//	3. 작성자		    : 오병래
//	4. 시스템 		    : 우편번호
//	5. Description      : 우편번호 검색
//---------------------------------------------------------------------------------------------
%>
<%@ page import="java.sql.*,javax.sql.DataSource,java.util.Properties, javax.naming.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	response.setHeader("Cache-Control", "no-cache");
	response.setHeader("Cache-Control", "no-store");
	response.setHeader("pragma", "no-cache");
%>
<html>
<head>
<style>
	A:link {text-decoration:none;color:#5f5f5f}
	A:hover{text-decoration:yes;color:#038afd}
	A:visited {text-decoration:none;color:#5f5f5f}
	td{font-size:10pt}
</style> 
<script language="javascript">
<!--
function fnReturnToMain(zipcode,juso)
{
    var rgParam = new Array;
    rgParam[0] = zipcode;
    rgParam[1] = juso;
    top.window.returnValue = rgParam;
    window.close();
    top.window.close();
    return;
}
//-->
</script>
</head>
<%
Connection conn = null;
ResultSet rset = null;
Statement stmt = null;
%>
<body text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#FFFFFF">
<form name="thisPage" method="post">
<table>
	<tr><td>
		<table style="BORDER-COLLAPSE: collapse" borderColor=#b4c7d4 cellSpacing=1 align=center border=1>
  			<tr bgcolor="D3D2CA" align="center">
				<td width="70">우편번호</td>
				<td width="80">시도</td>
				<td width="80">구군</td>
				<td>동</td>
				<td width="80">번지</td>
			</tr>
<%
try
{
	// Mysql DB 연결 정보
	String DB_URL = "jdbc:mysql://218.55.100.250/styledaco";
	String DB_USER = "styledaco";
	String DB_PASSWORD= "thesopt123";

	Class.forName("org.gjt.mm.mysql.Driver");
	conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
	stmt = conn.createStatement();

	String strZipcode = "", strJuso = "";
	String strFlag = request.getParameter("reqflag");		// 조회 조건
	String strVal = request.getParameter("reqVal");	// 조회 입력값
	String query = "SELECT postcode, "+
	                       "sido, "+
	                       "gugun, "+
	                       "dong, "+
	                       "bunji "+
                   "FROM postcode ";
	if (strFlag.equals("1")){			// 시도로 조회
			query += "WHERE sido like '%"+strVal+"%' ";
	} else if (strFlag.equals("2")){	// 구군으로 조회
		query += "WHERE gugun like '%"+strVal+"%' ";
	} else if (strFlag.equals("3")){	// 동으로 조회
		query += "WHERE dong like '%"+strVal+"%' ";
	}
	query += "ORDER BY sido, gugun, dong asc";
	rset = stmt.executeQuery(query);
	while(rset.next()){
		// 우편번호 style 선택 (100-754 or 100754)
		//strZipcode = rset.getString(1);
		strZipcode = rset.getString(1).substring(0,3) +"-"+ rset.getString(1).substring(3,6);
		strJuso = rset.getString(2) +" "+ rset.getString(3) +" "+rset.getString(4) +" "+ rset.getString(5);
%>		
			<tr style="cursor: pointer;" bgcolor="#F6F6F6" style="cursor:hand" onClick="javascript:fnReturnToMain('<%=strZipcode%>','<%=strJuso%>')" onMouseOver=this.style.backgroundColor="#E8EAFE" onMouseOut=this.style.backgroundColor=''>
				<td align="center"><%=rset.getString(1) %></td>
				<td align="center"><%=rset.getString(2)%></td>
				<td align="center"><%=rset.getString(3)%></td>
				<td align="center"><%=rset.getString(4)%></td>
				<td align="center"><%=rset.getString(5)%></td>
			</tr>
<%
	}
%>
		</table>
	</td></tr>
</table>
</form>
</body>
</html>
<%
}catch(Exception e)
{
	e.printStackTrace();
}finally{
	try{ rset.close(); stmt.close(); conn.close(); } catch(Exception ex){}
}
%>
